///*
// * Copyright © OpenAtom Foundation.
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *      http://www.apache.org/licenses/LICENSE-2.0
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
// * See the License for the specific language governing permissions and
// * limitations under the License.
// *
// */
//
//package io.iec.edp.caf.rpc;
//
//import io.iec.edp.caf.rpc.api.annotation.*;
//import io.iec.edp.caf.rpc.api.entity.GspRpcServiceDefinition;
//import io.iec.edp.caf.rpc.api.entity.GspServiceParamInfo;
//import io.iec.edp.caf.rpc.api.entity.GspServiceReturnInfo;
//import lombok.extern.slf4j.Slf4j;
//import lombok.var;
//
//import java.lang.annotation.Annotation;
//import java.lang.reflect.Method;
//import java.util.ArrayList;
//import java.util.List;
//
//@Slf4j
//public class RpcRegisterUtil {
//
//      //todo 没搜到有用的，后续去掉吧
//    public static List<GspRpcServiceDefinition> buildGspRpcServiceDefinition(Class<?> rpcInterface) {
//        List<GspRpcServiceDefinition> result = new ArrayList<>();
//
//        //获取接口上的GspServiceBundle的注解信息
//        GspServiceBundle gspServiceBundle = rpcInterface.getDeclaredAnnotation(GspServiceBundle.class);
//
//        if (gspServiceBundle != null) {
//            //接口方法集合,这个地方必须通过class来拿method,interface拿method后面拿不到方法的参数
//            var interMeds = rpcInterface.getMethods();
//            for (var iMethod : interMeds) {
//
//                var serviceId = "";
//                //得到这个方法之后，再获取这个方法的注解
//                Annotation annotation = iMethod.getAnnotation(RpcServiceMethod.class);
//                //判断这个注解是否为空或者，这个方法的注解是不是我们所写的这个注解
//                if (annotation != null && annotation instanceof RpcServiceMethod) {
//                    RpcServiceMethod serviceMethod = (RpcServiceMethod) annotation;
//                    serviceId = serviceMethod.serviceId();
//                }
//
//                if ("".equals(serviceId))
//                    serviceId = rpcInterface.getName() + "." + iMethod.getName();
//                GspRpcServiceDefinition srcInstance = new GspRpcServiceDefinition();
//                //这个地方必须存上实现类，不然的话后面找类没法找了
//                srcInstance.setImplementClass(rpcInterface.getName());
//                srcInstance.setInterfaceClass(rpcInterface.getName());
//                srcInstance.setId(serviceId + gspServiceBundle.serviceVersion());
//                srcInstance.setServiceId(serviceId);
//                srcInstance.setAsync(false);//todo:是否异步不能写死
//
//                srcInstance = buildGspServiceInstance(srcInstance, gspServiceBundle, iMethod);
//                result.add(srcInstance);
//
//                log.info("GspService: " + srcInstance.getId());
//            }
//        }
//
//        return result;
//    }
//
//    /**
//     * 构建GspServiceInstance对象
//     *
//     * @param srcInstance      GspServiceInstance对象
//     * @param gspServiceBundle GspServiceBundle注解
//     * @param m                方法
//     * @return GspServiceInstance对象
//     */
//    private static GspRpcServiceDefinition buildGspServiceInstance(GspRpcServiceDefinition srcInstance, GspServiceBundle gspServiceBundle, Method m) {
//        srcInstance.setApp(gspServiceBundle.applicationName());
//        srcInstance.setSu(gspServiceBundle.serviceUnitName());
//        srcInstance.setName(gspServiceBundle.serviceName());
//        srcInstance.setVersion(gspServiceBundle.serviceVersion());
//
//        //方法参数名集合
////        DefaultParameterNameDiscoverer discover = new DefaultParameterNameDiscoverer();
////        var paramsTruthNames = discover.getParameterNames(m);//m.getGenericParameterTypes();
//
//        //方法参数注解的集合
//        List<GspServiceParamInfo> listParamEntity = new ArrayList<GspServiceParamInfo>();
//
//        var params = m.getParameters();
//        for (var param : params) {
//            var annotation = param.getDeclaredAnnotationsByType(RpcParam.class);
//            if (annotation.length > 0) {
//                GspServiceParamInfo paramInfo = new GspServiceParamInfo();
//                paramInfo.setName(annotation[0].paramName());
//                paramInfo.setSerializeType(annotation[0].paramSerializeType());
//                paramInfo.setCustomClass(annotation[0].customSerializeTypeRef());
//                listParamEntity.add(paramInfo);
//            }
//        }
//
//        if (listParamEntity.size() == 0) {
//
//            var paramsAnnotation = m.getDeclaredAnnotationsByType(GspParamSerializeType.class);
//
//            if (paramsAnnotation != null) {
//                for (var p : paramsAnnotation) {
//                    GspServiceParamInfo paramInfo = new GspServiceParamInfo();
//                    paramInfo.setName(p.paramName());
//                    paramInfo.setSerializeType(p.paramSerializeType());
//                    paramInfo.setCustomClass(p.customSerializeTypeRef());
////                var pat = Arrays.stream(paramsAnnotation).filter((pa) -> pa.paramName().equals(p)).collect(toList());
////                //该参数有注解配置
////                if (pat.size() > 0) {
////                    paramInfo.setSerializeType(pat.get(0).paramSerializeType());
////                    paramInfo.setCustomClass(pat.get(0).customSerializeTypeRef());
////                }
//                    //GspServiceParamInfo集合
//                    listParamEntity.add(paramInfo);
//                }
//            }
//        }
//
//        srcInstance.setParameters(listParamEntity);
//
//        var returnAnnotation = m.getDeclaredAnnotation(GspReturnSerializeType.class);
//        GspServiceReturnInfo returnInfo = new GspServiceReturnInfo();
//        if (returnAnnotation != null) {
//            returnInfo.setSerializeType(returnAnnotation.paramSerializeType());
//            returnInfo.setCustomClass(returnAnnotation.customSerializeTypeRef());
//        }
//
//        srcInstance.setReturnInfo(returnInfo);
//
//        return srcInstance;
//    }
//}
